/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.extensionpoints.lang;

import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * Plugin activator.
 */
public class Activator extends AbstractUIPlugin {
	// The shared instance.
	/**
	 * 
	 */
	private static Activator plugin;
	
	// ID of the plugin
	/**
	 * 
	 */
	public static final String PLUGIN_ID = "com.cea.papyrus.extensionpoints.lang";

	// Resource bundle.
	/**
	 * 
	 */
	private static final String RESOURCE_NAME = PLUGIN_ID + ".ViewPlugin";
	
	/**
	 * 
	 */
	private ResourceBundle resourceBundle;
	
	/**
	 * The constructor.
	 */
	public Activator() {
		super();
		plugin = this;
		try {
			resourceBundle = ResourceBundle.getBundle(RESOURCE_NAME);
		} catch (MissingResourceException mre) {
			resourceBundle = null;
		}
	}

	/**
	 * This method is called upon plug-in activation.
	 * 
	 * @param context 
	 * 
	 * @throws Exception 
	 */
	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
		// showRuntimeLibraries();
		
		// Model Synchronizer
		/*
		// UMLModeler.getEditingDomain().addOperationListener(new ModelListener());
		// Force creation of the default instance of the manager
		// SynchronizerManager.getInstance();
		 */
	}

	/**
	 * This method is called when the plug-in is stopped.
	 * 
	 * @param context 
	 * 
	 * @throws Exception 
	 */
	@Override
	public void stop(BundleContext context) throws Exception {
		super.stop(context);
	}

	/**
	 * Returns the shared instance.
	 * 
	 * @return 
	 */
	public static Activator getDefault() {
		return plugin;
	}

	/**
	 * Returns the string from the plugin's resource bundle,
	 * or 'key' if not found.
	 * 
	 * @param key 
	 * 
	 * @return 
	 */
	public static String getResourceString(String key) {
		ResourceBundle bundle = Activator.getDefault().getResourceBundle();
		try {
			return (bundle != null) ? bundle.getString(key) : key;
		} catch (MissingResourceException e) {
			return key;
		}
	}

	/**
	 * Returns the plugin's resource bundle,.
	 * 
	 * @return 
	 */
	public ResourceBundle getResourceBundle() {
		return resourceBundle;
	}
}
